package com.we823.cms.common.web;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.convert.converter.Converter;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by ZhangYinxian on 2014/12/7.
 */
public class CustomDateConverter implements Converter<String,Date> {
    private Logger logger = LoggerFactory.getLogger(CustomDateConverter.class);
    @Override
    public Date convert(String source) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        simpleDateFormat.setLenient(false);
        if(source!=null){
            try{
                logger.debug("[{}] cover to date",source);
                return simpleDateFormat.parse(source);
            }catch (Exception ex){
                ex.printStackTrace();
            }
        }
        return null;
    }
}
